package group.program.register.username;

import group.program.Controller.RegisterController;
import group.program.Service.RegisterService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

class exist {

    @InjectMocks
    private RegisterController registerController;

    @Mock
    private RegisterService registerService; // 创建一个对 RegisterService 的 mock 实例

    @BeforeEach
    void setUp() {
        MockitoAnnotations.openMocks(this);
    }

    @Test
    void testExistUsername() {
        String existUserName = "jiaqi";

        // 模拟 registerService 中的方法
        when(registerService.isUserNameExist(existUserName)).thenReturn("用户名已存在");

        assertEquals("用户名已存在", registerController.checkIfUserNameExists(existUserName));
    }

    @Test
    void testNoExistUserName() {
        String noExistUserName = "jiaqii";

        // 模拟 registerService 中的方法
        when(registerService.isUserNameExist(noExistUserName)).thenReturn(null);

        assertNull(registerController.checkIfUserNameExists(noExistUserName));
    }
}
